from django.db import models


# Create your models here.
class Base_Entity(models.Model):
    id = models.AutoField(primary_key=True, db_comment='id')
    status = models.IntegerField(default=1, db_comment='状态,-1 删除,0无效,1有效')
    createUser = models.CharField(max_length=50, db_column='create_user')
    updateUser = models.CharField(max_length=50, db_column='update_user')
    createTime = models.DateTimeField(auto_now_add=True, db_column='create_time')
    updateTime = models.DateTimeField(auto_now=True, db_column='update_time')


class User(models.Model):
    id = models.AutoField(primary_key=True, db_comment='id')
    status = models.IntegerField(default=1, db_comment='状态,-1 删除,0无效,1有效')
    createUser = models.CharField(max_length=50, db_column='create_user')
    updateUser = models.CharField(max_length=50, db_column='update_user')
    createTime = models.DateTimeField(auto_now_add=True, db_column='create_time')
    updateTime = models.DateTimeField(auto_now=True, db_column='update_time')
    realName = models.CharField(max_length=100, db_column='real_name')
    nickName = models.CharField(max_length=100, db_column='nick_name')
    name = models.CharField(max_length=25)
    password = models.CharField(max_length=20)

    def __init__(self):
        super().__init__(self)


class User_Info(models.Model):
    id = models.AutoField(primary_key=True, db_comment='id')
    status = models.IntegerField(default=1, db_comment='状态,-1 删除,0无效,1有效')
    createUser = models.CharField(max_length=50, db_column='create_user')
    updateUser = models.CharField(max_length=50, db_column='update_user')
    createTime = models.DateTimeField(auto_now_add=True, db_column='create_time')
    updateTime = models.DateTimeField(auto_now=True, db_column='update_time')
    userId = models.ForeignKey(User, on_delete=models.CASCADE, max_length=36, db_column='user_id')
    age = models.IntegerField(default=0)
    phoneNumber = models.CharField(max_length=11, db_column='phone_number')
    email = models.EmailField()

    def __init__(self):
        super().__init__(self)


class Place(models.Model):
    id = models.AutoField(primary_key=True, db_comment='id')
    status = models.IntegerField(default=1, db_comment='状态,-1 删除,0无效,1有效')
    createUser = models.CharField(max_length=50, db_column='create_user')
    updateUser = models.CharField(max_length=50, db_column='update_user')
    createTime = models.DateTimeField(auto_now_add=True, db_column='create_time')
    updateTime = models.DateTimeField(auto_now=True, db_column='update_time')
    placeName = models.CharField(max_length=100, db_column='place_name')
    placeCode = models.CharField(max_length=10, db_column='place_code')
    # placeId = models.CharField(max_length=36)
    # city = models.CharField(max_length=100)
    # country = models.CharField(max_length=100)
    pPlaceId = models.CharField(max_length=36, db_column='p_place_id')

    def __init__(self):
        super().__init__(self)


class Publisher(models.Model):
    id = models.AutoField(primary_key=True, db_comment='id')
    status = models.IntegerField(default=1, db_comment='状态,-1 删除,0无效,1有效')
    createUser = models.CharField(max_length=50, db_column='create_user')
    updateUser = models.CharField(max_length=50, db_column='update_user')
    createTime = models.DateTimeField(auto_now_add=True, db_column='create_time')
    updateTime = models.DateTimeField(auto_now=True, db_column='update_time')
    name = models.CharField(max_length=100)
    address = models.CharField(max_length=100, null=True)
    province = models.CharField(max_length=100, null=True)
    city = models.CharField(max_length=100, null=True)
    town = models.CharField(max_length=100, null=True)
    country = models.CharField(max_length=100, null=True)


class Author(models.Model):
    id = models.AutoField(primary_key=True, db_comment='id')
    status = models.IntegerField(default=1, db_comment='状态,-1 删除,0无效,1有效')
    createUser = models.CharField(max_length=50, db_column='create_user')
    updateUser = models.CharField(max_length=50, db_column='update_user')
    createTime = models.DateTimeField(auto_now_add=True, db_column='create_time')
    updateTime = models.DateTimeField(auto_now=True, db_column='update_time')
    name = models.CharField(max_length=100)
    familyName = models.CharField(max_length=50, db_column='family_name')
    givenName = models.CharField(max_length=100, db_column='given_name')
    age = models.IntegerField(default=0)
    phoneNumber = models.CharField(max_length=11, db_column='phone_number')
    email = models.EmailField()
    provinceCode = models.CharField(max_length=10, db_column='province_code')
    cityCode = models.CharField(max_length=10, null=True, db_column='city_code')


class Book(models.Model):
    id = models.AutoField(primary_key=True, db_comment='id')
    status = models.IntegerField(default=1, db_comment='状态,-1 删除,0无效,1有效')
    createUser = models.CharField(max_length=50, db_column='create_user')
    updateUser = models.CharField(max_length=50, db_column='update_user')
    createTime = models.DateTimeField(auto_now_add=True, db_column='create_time')
    updateTime = models.DateTimeField(auto_now=True, db_column='update_time')
    title = models.CharField(max_length=100)
    authorId = models.ForeignKey(Author, on_delete=models.CASCADE, null=True, db_column='author_id')
    price = models.DecimalField(max_digits=28, default=0.0, decimal_places=2, null=True)
    publisherId = models.ForeignKey(Publisher, max_length=36, on_delete=models.CASCADE, db_column='publisher_id')
    publisherDate = models.DateField(null=True, db_column='publisher_date')
    publisherAddress = models.CharField(max_length=100, null=True, db_column='publisher_address')
    totalWordsCount = models.IntegerField(default=0, db_column='total_words_count')


# 活动举办方: 0 系统,1 商家,2商家联盟
class Activity(models.Model):
    id = models.AutoField(primary_key=True, db_comment='id')
    status = models.IntegerField(default=1, db_comment='状态,-1 删除,0无效,1有效')
    createUser = models.CharField(max_length=50, db_column='create_user')
    updateUser = models.CharField(max_length=50, db_column='update_user')
    createTime = models.DateTimeField(auto_now_add=True, db_column='create_time')
    updateTime = models.DateTimeField(auto_now=True, db_column='update_time')
    title = models.CharField(max_length=100)
    description = models.TextField(null=True)
    publisherId = models.ForeignKey(Publisher, on_delete=models.CASCADE, db_comment='活动举办方id',
                                    db_column='publisher_id')
    publisherType = models.IntegerField(default=0, db_comment='活动举办方类型', db_column='publisher_type')


class Price_History(models.Model):
    id = models.AutoField(primary_key=True, db_comment='id')
    status = models.IntegerField(default=1, db_comment='状态,-1 删除,0无效,1有效')
    createUser = models.CharField(max_length=50, db_column='create_user')
    updateUser = models.CharField(max_length=50, db_column='update_user')
    createTime = models.DateTimeField(auto_now_add=True, db_column='create_time')
    updateTime = models.DateTimeField(auto_now=True, db_column='update_time')
    price = models.DecimalField(max_digits=28, default=0.0, decimal_places=2, null=True)
    bookId = models.ForeignKey(Book, on_delete=models.CASCADE, null=True, db_column='book_id')
    startDate = models.DateField(null=True, db_column='start_date')
    endDate = models.DateField(null=True, db_column='end_date')


class Receive_Address(models.Model):
    id = models.AutoField(primary_key=True, db_comment='id')
    status = models.IntegerField(default=1, db_comment='状态,-1 删除,0无效,1有效')
    createUser = models.CharField(max_length=50, db_column='create_user')
    updateUser = models.CharField(max_length=50, db_column='update_user')
    createTime = models.DateTimeField(auto_now_add=True, db_column='create_time')
    updateTime = models.DateTimeField(auto_now=True, db_column='update_time')
    address = models.CharField(max_length=100, null=True)
    provinceCode = models.CharField(max_length=10, db_column='province_code')
    cityCode = models.CharField(max_length=10, db_column='city_code')
    userId = models.CharField(max_length=36, db_column='user_id')
    phoneNumber = models.CharField(max_length=11, db_column='phone_number')
    receiverName = models.CharField(max_length=20, db_column='receiver_name')


class Order(models.Model):
    id = models.AutoField(primary_key=True, db_comment='id')
    status = models.IntegerField(default=1, db_comment='状态,-1 删除,0无效,1有效')
    createUser = models.CharField(max_length=50, db_column='create_user')
    updateUser = models.CharField(max_length=50, db_column='update_user')
    createTime = models.DateTimeField(auto_now_add=True, db_column='create_time')
    updateTime = models.DateTimeField(auto_now=True, db_column='update_time')
    userId = models.CharField(max_length=36, db_column='user_id')
    orderCode = models.CharField(max_length=30, db_column='order_code')
    totalMoney = models.DecimalField(max_digits=28, default=0.0, decimal_places=2, null=True, db_column='total_money')
    orderDate = models.DateField(null=True, db_column='order_date')
    totalDiscount = models.DecimalField(max_digits=28, default=0.0, decimal_places=2, null=True,
                                        db_column='total_discount')
    submitDate = models.DateField(null=True, db_column='submit_date')
    receiveAddressId = models.ForeignKey(Receive_Address, on_delete=models.CASCADE, db_column='receive_address_id')


class Order_Item(models.Model):
    id = models.AutoField(primary_key=True, db_comment='id')
    status = models.IntegerField(default=1, db_comment='状态,-1 删除,0无效,1有效')
    createUser = models.CharField(max_length=50, db_column='create_user')
    updateUser = models.CharField(max_length=50, db_column='update_user')
    createTime = models.DateTimeField(auto_now_add=True, db_column='create_time')
    updateTime = models.DateTimeField(auto_now=True, db_column='update_time')
    orderId = models.ForeignKey(Order, on_delete=models.CASCADE, db_column='order_id')
    itemCode = models.CharField(max_length=30, db_column='item_code')
    totalMoney = models.DecimalField(max_digits=28, default=0.0, decimal_places=2, null=True, db_column='total_money')
    bookId = models.ForeignKey(Book, on_delete=models.CASCADE, max_length=36, null=True, db_column='book_id')
    priceId = models.ForeignKey(Price_History, on_delete=models.CASCADE, max_length=36, null=True, db_column='price_id')
    discount = models.DecimalField(max_digits=28, default=0.0, decimal_places=2, null=True, db_column='discount')
    activityId = models.ForeignKey(Activity, on_delete=models.CASCADE, max_length=36, null=True,
                                   db_column='activity_id')
    orderStatus = models.IntegerField(default=0, db_comment='订单完成状态,0 下单,1 拣货,2发货,3寄存,4签收',
                                      db_column='order_status')

